home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
includes
/
mobileFunctions.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
11KB
|
259 lines
<?php
/**
* Common functions used by scripts displaying mobile devices pages
*
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2008 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.3.0
*/
define('IEMOBILE_TOP_CONTROLS_HEIGHT',50);
/**
* @desc Insert header, body and top controls for mobile pages
*
* @param array $parameters: array of parameters:
* 'javascript': javascript code to be embed into <head></head> (without <script> tag
* 'style': css style to be embed into <head></head> (without <style> tag
* 'bodyExtraHTML': HTML codeto be embed within <body> tag
* 'ping': mixed: true/false to include or not a periodic ping to server, 'auto' to include depending on script
* 'noTopControls': true not to include top header
* 'topControlsLabel': HTML code to be included into top header label area
* 'topControlsExtra': HTML code to be included into top header extra area
* 'title': page title
* 'noUpdateOrientation': set to indicate orientation update script won't be included
*/
function mfInsertHead($parameters=array()){
// Asynchronous request: just return XML header
if(isset($_POST['asyncRequest'])){
cfAsyncHeader();
return;
}
@header('P3P: policyref="/w3c/p3p.xml",CP="NON COR CURa OUR NOR NAV"');
@header('Connection: Keep-Alive');
@header('Keep-Alive: timeout=15, max=2000');
@header('Proxy-Connection: Keep-Alive');
if(!isset($parameters['ping'])) $parameters['ping']='auto';
// Context (login, menu, resource, view)
if (isset($parameters['context'])) $context=$parameters['context'];
elseif($_SERVER['SCRIPT_NAME']=='/login.php') $context='login';
elseif($_SERVER['SCRIPT_NAME']=='/mainFrame.php'||$_SERVER['SCRIPT_NAME']=='/index.php') $context='menu';
else $context='resource';
//$isResource=(substr($_SERVER['PHP_SELF'],0,5)=='/res/' && isset($_SESSION['activeResourceId']));
/**
* HTML Output
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<?php
// Insert extra meta tags
if(cfRGetVar('meta')&&!cfBGetVar('name')=='iPhone') echo cfRGetVar('meta');
if(isset($_ENV['meta'])) echo $_ENV['meta'];
if(cfBGetVar('extraHead')) echo cfBGetVar('extraHead');
// Title
if(isset($parameters['title'])) $title=$parameters['title'];
elseif ($context=='resource'||$context=='view') $title=cfUTF8Encode(cfRGetVar('name'));
else $title=cfGGetVar('pageTitle');
echo '<title>'.$title.'</title>'."\n";
// Theme
echo '<link rel="stylesheet" type="text/css" media="all" href="/themes/mobile/theme.css?v='.cfGGetVar('appVersion').'&browser='.cfBGetVar('name')."\">\n";
if(cfBGetVar('mobileTheme')) echo '<link rel="stylesheet" media="all" type="text/css" href="/themes/mobile/'.cfBGetVar('mobileTheme').'/theme.css?v='.cfGGetVar('appVersion')."\">\n";
//if(cfBGetVar('name')=='iPhone') echo '<link rel="stylesheet" media="all" type="text/css" href="/themes/mobile/IEMobile/theme.css?v='.cfGGetVar('appVersion').'&rnd='.rand()."\">\n";
// Common js functions
if(!cfBGetVar('inlineJS')) echo cfScriptLink('mCommon.js');
// Javascript
?><script type="text/javascript" language="javascript"><?php
if(cfBGetVar('name')=='iPhone') echo 'setTimeout("D.body.onload=window.scrollTo(0,1)",10);';
if(cfBGetVar('inlineJS')) echo file_get_contents(cfAppDocRoot().'/js/mCommon.js'); // inline javascript (IE Mobile 5)
// insert javascript resource id (used by async requests)
if(substr($_SERVER['PHP_SELF'],0,5)=='/res/' && isset($_SESSION['activeResourceId'])) echo 'var resId="'.$_SESSION['activeResourceId']."\";\n";
// Extra javascript
if(isset($parameters['javascript'])) echo $parameters['javascript'];
// Periodic server ping
if(!isset($parameters['ping']) || $parameters['ping']===true || ($parameters['ping']==='auto' &&
($context=='resource' || $context=='view' || $_SERVER['SCRIPT_NAME']=='/index.php'))) {
echo "var pingInterval=".(max(cfGGetVar('clientPingInterval'),cfBGetVar('clientPingInterval'),10)*1000).";\n";
echo 'setTimeout("if(window.ping) ping("+pingInterval+")",pingInterval);';
}
// iPhone orientation zoom adaptation script
if(!isset($parameters['noUpdateOrientation']) && cfBGetVar('name')=='iPhone'){?>
function updateOrientation(){
if(window.orientation==undefined) return;
if(Math.abs(orientation)==90) {
dgn('viewport').setAttribute("content", "width=480, height=268, user-scalable=yes,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0");
D.body.style.height='268px';
}
else {
dgn('viewport').setAttribute("content", "width=320, height=416, user-scalable=yes,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0");
D.body.style.height='416px';
}
}
<?php
}
?></script><?php
// Extra style
if(isset($parameters['style'])) echo "<style>\n".$parameters['style']."\n</style>\n";
// Close head
if(!isset($parameters['bodyExtraHTML'])) $parameters['bodyExtraHTML']='';
if(cfBGetVar('name')=='iPhone') $parameters['bodyExtraHTML'].=' onorientationchange="if(W.updateOrientation) updateOrientation()"';
echo "</head><body ".$parameters['bodyExtraHTML'].">\n";
// Asynchronous request through iframe (PSP)
if(cfBGetVar('ajax')==='iframe') echo '<iframe name="ajaxIFrame" style="visibility:hidden;width:1;height:1" border=0></iframe><form id="ajaxIFrameForm" style="display:none" method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data" target="ajaxIFrame"><input name="XMLHttpScriptRequest"></form>';
// Resource common top controls
if(!isset($parameters['noTopControls'])){
mfInsertTopControls(
$context,
isset($parameters['topControlsLabel'])?$parameters['topControlsLabel']:false,
isset($parameters['topControlsExtra'])?$parameters['topControlsExtra']:false
);
}
// Send to browser
flush();
}
/**
* @desc Insert HTML code for resources top controls
* @param $context: 'resource' (default), 'menu', 'view', 'login'
*
*/
function mfInsertTopControls($context='resource',$capt=false,$extra=false){
?>
<table id="winBar" cellspacing=0 cellpadding=0>
<colgroup><col width="1%"><col width="98%"><col width="1%"></colgroup><tr>
<td id="wbI" style="white-space:nowrap">
<?php
// Top left
if($context=='menu'||$context=='login') echo '<img src="'.outIcon('appIcon32mobile').'" height="32" width="32"/>'."\n";
if($context=='view'||$context=='resource') echo mfButton(false,"/index.php",outIcon("home"))."\n";
if($context=='view') echo ' '.mfButton(false,'javascript:mwl.liSel(this);document.location=\'/res/'.cfRGetVar('type').'/'.cfRGetVar('subType').'/index.php?resId='.$_SESSION['activeResourceId'].'\'',cfRGetVar('resourceIcon'))."\n";
?>
</td>
<td id="wbC"><?php
// Main caption
if($capt!==false) echo $capt;
elseif ($context=='login') echo cfCaption('loginSelectAccount');
elseif ($context=='menu') echo cfCaption('genResources');
else echo ' ';
?>
</td><td id="wbE"><?php
// Extra buttons
if($extra!==false) echo $extra;
// Logout button
elseif ($context=='menu')echo mfButton(false,'javascript:document.logoutForm.submit()',outIcon('logout'));
?></td></tr></table>
<?php
}
/**
* @desc Display a page indicating that resource is not compatible with mobile browsers
*
*/
function mfDisplayResourceNotCompatiblePage(){
mfInsertHead();
echo '<table style="height:70%;width:100%"><tr valign="middle"><td valign="middle" align="center">'.outImage(outIcon('mobileNo')).'</td></tr></table></body></html>';
exit;
}
/**
* @return string: code
* @param string $caption : button's caption (utf-8 encoded)
* @param string $action : optional : action (href)
* @param string $imgSrc : optional : path to button's image
* @param string $extraHTML : optional : extra HTML code included in button definition
* @param string $state: false: normal, 'disabled' or 'on'
* @desc Insert HTML code for a button
*/
function mfButton($caption,$href='#',$imgSrc=false,$extraHTML=false,$state=false){
//Format : <a class="button"><img src="icon"/>text</a>
$output='<a '.$extraHTML.' class="';
if($state=='on') $output.='btSel';
elseif($state=='disabled') $output.='btDisabled';
else $output.='bt';
$output.='" href="';
if($state=='disabled') {
if(substr($href,0,11)=='javascript:') $output.='javascript://'.substr($href,11);
else $output.='javascript://#'.$href;
}
else $output.=$href;
$output.='"><img src="'.(($imgSrc)?$imgSrc.'" class="ico"':'/gfx/v.gif"').' alt="" />';
if($caption) $caption='<span>'.$caption.'</span>';
return $output.str_replace(' ',' ',$caption).'</a>';
}
/**
* @desc Return HTML code for list table definition
*
* @param $extraHTML
* @return string HTMl code
*/
function mfListTable($extraHTML=''){return '<table class="liTable" cellspacing=0 cellpadding=0 '.$extraHTML.'><colgroup><col width="1"><col width="*"><col width="1">';}
/**
* @desc List item HTML
*
* @param string $extraHTML: HTML inserted into (topmost) tr element
* @param string $lContent: left-side HTML
* @param string $lAction: HTML inserted into left td
* @param string $cContent: central HTML
* @param string $cAction: HTML inserted into central td
* @param string $rContent: right-side HTML
* @param string $rAction: HTML inserted into right td
* @return string HTML code
*/
function mfListItem($extraHTML,$lContent,$lAction=false,$cContent=false,$cAction=false,$rContent='',$rAction=false){
if(strpos($extraHTML,'class=')!==false) $output='<tr '.$extraHTML.'>'; else $output='<tr class="li" '.$extraHTML.'>';
$output.='<td class="lil" '.$lAction.'>'.$lContent.'</td>';
if($rContent){
$output.='<td class="lic" '.$cAction.'>'.$cContent.'</td>';
$output.='<td class="lir" '.$rAction.'>'.$rContent.'</td>';
}
else $output.='<td class="lir" colspan="2" '.$cAction.' style="text-align:left">'.$cContent.'</td>';
return $output."</tr>";
}
/**
* @desc Return a list item spacer
*
* @return string HTML code
*/
function mfListSpacer($caption=false){
if(!$caption) return mfListItem('class="liSpacer"','');
return '<tr><td colspan="3" style="height:1.6em;vertical-align:bottom" class="lit">'.$caption.'</td></tr>';
}
?>